package com.flag.liutao.modules.equip.controller;


import com.flag.liutao.common.domain.IdParam;
import com.flag.liutao.common.domain.IdsParam;
import com.flag.liutao.common.domain.QueryParam;
import com.flag.liutao.common.domain.ResponseResult;
import com.flag.liutao.modules.equip.param.ClothingParam;
import com.flag.liutao.modules.equip.service.IClothingService;
import com.flag.liutao.modules.student.param.DeptParam;
import com.flag.liutao.modules.student.vo.DepartmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author godM
 * @since 2022-12-19
 */
@RestController
@RequestMapping("/admin/clothing")
@RequiredArgsConstructor
@Api(tags = "服装管理")
public class ClothingController {

    private final IClothingService clothingService;

    /**
     * 获取服装信息
     * @param param
     * @return
     */
    @GetMapping("page")
    @PreAuthorize("hasAuthority('sys_power:clothing_R')")
    @ApiOperation(value="分页获取服装信息",notes = "服装管理：分页获取服装信息")
    public ResponseResult<Map<String,Object>> getDeptPage(QueryParam param){
        Map<String,Object> map = clothingService.getPage(param.getPage(),param.getLimit(),param.getKeyword());
        return ResponseResult.ok(map);
    }



    @PostMapping("add")
    @PreAuthorize("hasAuthority('sys_power:clothing_C')")
    @ApiOperation(value="添加服装信息",notes = "服装管理：添加服装信息")
    public ResponseResult<Boolean> addDept(@Validated @RequestBody ClothingParam param){
        clothingService.add(param);
        return ResponseResult.ok();
    }

    @PostMapping("edit")
    @PreAuthorize("hasAuthority('sys_power:clothing_U')")
    @ApiOperation(value="修改服装信息",notes = "服装管理：修改服装信息")
    public ResponseResult<Boolean> editDept(@Validated @RequestBody ClothingParam param){
        clothingService.edit(param);
        return ResponseResult.ok();
    }

    @PostMapping("del")
    @PreAuthorize("hasAuthority('sys_power:clothing_C')")
    @ApiOperation(value="删除服装信息",notes = "服装管理：删除服装信息")
    public ResponseResult<Boolean> delDept(@Validated @RequestBody IdParam param){
        clothingService.del(param.getId());
        return ResponseResult.ok();
    }

    @PostMapping("dels")
    @PreAuthorize("hasAuthority('sys_power:clothing_C')")
    @ApiOperation(value="批量删除二服装信息",notes = "服装管理：批量删除服装信息")
    public ResponseResult<Boolean> delsDept(@Validated @RequestBody IdsParam param){

        for (Long id : param.getIds()) {
            clothingService.del(id);
        }
        return ResponseResult.ok();
    }
}
